package com.lhy.tool.autoconfigation;

import com.lhy.tool.generator.AbstractControllerGenerator;
import com.lhy.tool.generator.AbstractModelGenerator;
import com.lhy.tool.generator.AbstractServiceGenerator;
import com.lhy.tool.generator.impl.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@EnableConfigurationProperties({GeneratorProperties.class})
@Import({GeneratorConfiguration.class,GeneratorDataBaseAutoConfiguration.class})
public class GeneratorAutoConfiguration {
	
	@Bean
	@ConditionalOnMissingBean
	@ConditionalOnProperty(prefix = "crud-gen.global-config", name = "controller-enabled",havingValue="true", matchIfMissing = true)
	public AbstractControllerGenerator controllerBuilder(){
		return new DefaultControllerGenerator();
	}
	
	@Bean
	@ConditionalOnMissingBean
	@ConditionalOnProperty(prefix = "crud-gen.global-config", name = "service-enabled",havingValue="true", matchIfMissing = true)
	public AbstractServiceGenerator serviceGenerator(){
		return new DefaultServiceGenerator();
	}
	
	@Bean
	@ConditionalOnMissingBean
	@ConditionalOnProperty(prefix = "crud-gen.global-config", name = "view-enabled",havingValue="true", matchIfMissing = true)
	public DefaultVueViewGenerator vueViewGenerator(){
		return new DefaultVueViewGenerator();
	}

	@Bean
	@ConditionalOnMissingBean
	@ConditionalOnProperty(prefix = "crud-gen.global-config", name = "view-enabled",havingValue="true", matchIfMissing = true)
	public DefaultVueUtilGenerator vueUtilGenerator(){
		return new DefaultVueUtilGenerator();
	}

	@Bean
	@ConditionalOnMissingBean
	@ConditionalOnProperty(prefix = "crud-gen.global-config", name = "mapper-enabled",havingValue="true", matchIfMissing = true)
	public DefaultJavaMapperGenerator mapperGenerator(){
		return new DefaultJavaMapperGenerator();
	}

	@Bean
	@ConditionalOnMissingBean
	@ConditionalOnProperty(prefix = "crud-gen.global-config", name = "mapper-xml-enabled",havingValue="true", matchIfMissing = true)
	public DefaultMapperXmlGenerator mapperXmlGenerator(){
		return new DefaultMapperXmlGenerator();
	}

	@Bean
	@ConditionalOnMissingBean
	@ConditionalOnProperty(prefix = "crud-gen.global-config", name = "model-enabled",havingValue="true", matchIfMissing = true)
	public AbstractModelGenerator modelGenerator(){
		return new DefaultModelGenerator();
	}


}
